package com.meme.app;

import javax.swing.ImageIcon;

import org.apache.log4j.Logger;

import com.meme.editor.model.sprite2d.Module;

import java.util.Hashtable;

public class ResourceManager 
{
	static Logger logger = Logger.getLogger (ResourceManager.class);
	
	static Hashtable<String, ImageIcon> mIconTable     = new Hashtable<String, ImageIcon> ();
	static Hashtable<String, String>    mFilenameTable = new Hashtable<String, String> ();
	static
	{
		mFilenameTable.put("save", "icons/save.gif");
		mFilenameTable.put("open", "icons/open.gif");
		mFilenameTable.put("new", "icons/new.gif");
		mFilenameTable.put("close", "icons/close.gif");
		mFilenameTable.put("add", "icons/add.png");
		mFilenameTable.put("insert", "icons/insert.png");
		mFilenameTable.put("delete", "icons/del.png");
		mFilenameTable.put("up", "icons/up.png");
		mFilenameTable.put("down", "icons/down.png");
	}
	
	//
	
	private ResourceManager ()
	{
		
	}
	
	public static ImageIcon getIcon (String iconname)
	{
		String filename = mFilenameTable.get (iconname);
		
		logger.assertLog(filename != null, "The icon with name [" + iconname + "] is not registered." );
		
	
		ImageIcon icon = mIconTable.get(filename);
		if ( icon == null )
		{
			icon = new ImageIcon (ClassLoader.getSystemResource(filename));
			mIconTable.put (filename, icon);
		}
		
		logger.assertLog(icon != null, "The icon with filename [" + filename + "] is not created." );
		
		return icon;
	}
}
